import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }
        System.out.println(sortTnt(arr));
    }
    public static int sortTnt(int[] arr) {
        int count = 0;
        for(int i = 0; i < arr.length; i++) {
            for(int j =  1; j < arr.length - i; j++) {
                if(arr[j - 1] > arr[j]) {
                    count += arr[j - 1];
                    int tmp = arr[j - 1];
                    arr[j - 1] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
        return count;
    }
}
